﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace QLNHK.BLL
{
	public partial class HoKhau : Ent_Base, ICloneable
	{
        #region Variables
        
		private int _iD;
		private int _loaiHoKhauID;
		private int _soSoHoKhau;
		private string _diaChi = string.Empty;
		private int _tinhTPID;
		private int _quanHuyenID;
		private int _phuongXaID;
		private int _toDanPhoID;
		private int _hSHKSo;
		private string _luuGocTap = string.Empty;
		private string _quyenSo = string.Empty;
		private int _toSo;
		private string _chiBo = string.Empty;
		private string _ghiChu = string.Empty;
		private int _canBoQuanLyID;
		private bool _isDelete;
		private int _truongCongAnID;
        
        #endregion
    
        //---------------------------------------------------------------------------------------------
        
		#region Properties.
		
		public int ID 
        { 
            get { return  _iD; } 
            set
            {
                _iD = value;
                OnPropertyChanged("ID");
            }
        }
		public int LoaiHoKhauID 
        { 
            get { return  _loaiHoKhauID; } 
            set
            {
                _loaiHoKhauID = value;
                OnPropertyChanged("LoaiHoKhauID");
            }
        }
		public int SoSoHoKhau 
        { 
            get { return  _soSoHoKhau; } 
            set
            {
                _soSoHoKhau = value;
                OnPropertyChanged("SoSoHoKhau");
            }
        }
		public string DiaChi 
        { 
            get { return  _diaChi; } 
            set
            {
                _diaChi = value;
                OnPropertyChanged("DiaChi");
            }
        }
		public int TinhTPID 
        { 
            get { return  _tinhTPID; } 
            set
            {
                _tinhTPID = value;
                OnPropertyChanged("TinhTPID");
            }
        }
		public int QuanHuyenID 
        { 
            get { return  _quanHuyenID; } 
            set
            {
                _quanHuyenID = value;
                OnPropertyChanged("QuanHuyenID");
            }
        }
		public int PhuongXaID 
        { 
            get { return  _phuongXaID; } 
            set
            {
                _phuongXaID = value;
                OnPropertyChanged("PhuongXaID");
            }
        }
		public int ToDanPhoID 
        { 
            get { return  _toDanPhoID; } 
            set
            {
                _toDanPhoID = value;
                OnPropertyChanged("ToDanPhoID");
            }
        }
		public int HSHKSo 
        { 
            get { return  _hSHKSo; } 
            set
            {
                _hSHKSo = value;
                OnPropertyChanged("HSHKSo");
            }
        }
		public string LuuGocTap 
        { 
            get { return  _luuGocTap; } 
            set
            {
                _luuGocTap = value;
                OnPropertyChanged("LuuGocTap");
            }
        }
		public string QuyenSo 
        { 
            get { return  _quyenSo; } 
            set
            {
                _quyenSo = value;
                OnPropertyChanged("QuyenSo");
            }
        }
		public int ToSo 
        { 
            get { return  _toSo; } 
            set
            {
                _toSo = value;
                OnPropertyChanged("ToSo");
            }
        }
		public string ChiBo 
        { 
            get { return  _chiBo; } 
            set
            {
                _chiBo = value;
                OnPropertyChanged("ChiBo");
            }
        }
		public string GhiChu 
        { 
            get { return  _ghiChu; } 
            set
            {
                _ghiChu = value;
                OnPropertyChanged("GhiChu");
            }
        }
		public int CanBoQuanLyID 
        { 
            get { return  _canBoQuanLyID; } 
            set
            {
                _canBoQuanLyID = value;
                OnPropertyChanged("CanBoQuanLyID");
            }
        }
		public bool IsDelete 
        { 
            get { return  _isDelete; } 
            set
            {
                _isDelete = value;
                OnPropertyChanged("IsDelete");
            }
        }
		public int TruongCongAnID 
        { 
            get { return  _truongCongAnID; } 
            set
            {
                _truongCongAnID = value;
                OnPropertyChanged("TruongCongAnID");
            }
        }
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Methods
		protected static List<HoKhau> ConvertToCollection(IDataReader reader)
		{
			List<HoKhau> collection = new List<HoKhau>();
			while (reader.Read())
			{
				HoKhau entity = new HoKhau();
				if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
				if (!reader.IsDBNull(reader.GetOrdinal("LoaiHoKhauID"))) entity.LoaiHoKhauID = reader.GetInt32(reader.GetOrdinal("LoaiHoKhauID"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoSoHoKhau"))) entity.SoSoHoKhau = reader.GetInt32(reader.GetOrdinal("SoSoHoKhau"));
				if (!reader.IsDBNull(reader.GetOrdinal("DiaChi"))) entity.DiaChi = reader.GetString(reader.GetOrdinal("DiaChi"));
				if (!reader.IsDBNull(reader.GetOrdinal("TinhTPID"))) entity.TinhTPID = reader.GetInt32(reader.GetOrdinal("TinhTPID"));
				if (!reader.IsDBNull(reader.GetOrdinal("QuanHuyenID"))) entity.QuanHuyenID = reader.GetInt32(reader.GetOrdinal("QuanHuyenID"));
				if (!reader.IsDBNull(reader.GetOrdinal("PhuongXaID"))) entity.PhuongXaID = reader.GetInt32(reader.GetOrdinal("PhuongXaID"));
				if (!reader.IsDBNull(reader.GetOrdinal("ToDanPhoID"))) entity.ToDanPhoID = reader.GetInt32(reader.GetOrdinal("ToDanPhoID"));
				if (!reader.IsDBNull(reader.GetOrdinal("HSHKSo"))) entity.HSHKSo = reader.GetInt32(reader.GetOrdinal("HSHKSo"));
				if (!reader.IsDBNull(reader.GetOrdinal("LuuGocTap"))) entity.LuuGocTap = reader.GetString(reader.GetOrdinal("LuuGocTap"));
				if (!reader.IsDBNull(reader.GetOrdinal("QuyenSo"))) entity.QuyenSo = reader.GetString(reader.GetOrdinal("QuyenSo"));
				if (!reader.IsDBNull(reader.GetOrdinal("ToSo"))) entity.ToSo = reader.GetInt32(reader.GetOrdinal("ToSo"));
				if (!reader.IsDBNull(reader.GetOrdinal("ChiBo"))) entity.ChiBo = reader.GetString(reader.GetOrdinal("ChiBo"));
				if (!reader.IsDBNull(reader.GetOrdinal("GhiChu"))) entity.GhiChu = reader.GetString(reader.GetOrdinal("GhiChu"));
				if (!reader.IsDBNull(reader.GetOrdinal("CanBoQuanLyID"))) entity.CanBoQuanLyID = reader.GetInt32(reader.GetOrdinal("CanBoQuanLyID"));
				if (!reader.IsDBNull(reader.GetOrdinal("IsDelete"))) entity.IsDelete = reader.GetBoolean(reader.GetOrdinal("IsDelete"));
				if (!reader.IsDBNull(reader.GetOrdinal("TruongCongAnID"))) entity.TruongCongAnID = reader.GetInt32(reader.GetOrdinal("TruongCongAnID"));
				collection.Add(entity);
			}
			reader.Close();
			return collection;
		}
		
		public static bool Find(List<HoKhau> collection, int iD)
        {
            foreach (HoKhau item in collection)
            {
                if (item.ID == iD)
                {
                    return true;
                }
            }

            return false;
        }
		
		public static void UpdateDataSet(DataSet ds)
        {
            string insert = "Insert INTO t_HoKhau VALUES(@LoaiHoKhauID, @SoSoHoKhau, @DiaChi, @TinhTPID, @QuanHuyenID, @PhuongXaID, @ToDanPhoID, @HSHKSo, @LuuGocTap, @QuyenSo, @ToSo, @ChiBo, @GhiChu, @CanBoQuanLyID, @IsDelete, @TruongCongAnID)";
            string update = "UPDATE t_HoKhau SET LoaiHoKhauID = @LoaiHoKhauID, SoSoHoKhau = @SoSoHoKhau, DiaChi = @DiaChi, TinhTPID = @TinhTPID, QuanHuyenID = @QuanHuyenID, PhuongXaID = @PhuongXaID, ToDanPhoID = @ToDanPhoID, HSHKSo = @HSHKSo, LuuGocTap = @LuuGocTap, QuyenSo = @QuyenSo, ToSo = @ToSo, ChiBo = @ChiBo, GhiChu = @GhiChu, CanBoQuanLyID = @CanBoQuanLyID, IsDelete = @IsDelete, TruongCongAnID = @TruongCongAnID WHERE ID = @ID";
            string delete = "DELETE FROM t_HoKhau WHERE ID = @ID";

			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();

            System.Data.Common.DbCommand InsertCommand = db.GetSqlStringCommand(insert);
			db.AddInParameter(InsertCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@LoaiHoKhauID", SqlDbType.Int, "LoaiHoKhauID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoSoHoKhau", SqlDbType.Int, "SoSoHoKhau", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DiaChi", SqlDbType.NVarChar, "DiaChi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TinhTPID", SqlDbType.Int, "TinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuanHuyenID", SqlDbType.Int, "QuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@PhuongXaID", SqlDbType.Int, "PhuongXaID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ToDanPhoID", SqlDbType.Int, "ToDanPhoID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HSHKSo", SqlDbType.Int, "HSHKSo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@LuuGocTap", SqlDbType.NVarChar, "LuuGocTap", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuyenSo", SqlDbType.NVarChar, "QuyenSo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ToSo", SqlDbType.Int, "ToSo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ChiBo", SqlDbType.NVarChar, "ChiBo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@GhiChu", SqlDbType.NVarChar, "GhiChu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TruongCongAnID", SqlDbType.Int, "TruongCongAnID", DataRowVersion.Current);

            System.Data.Common.DbCommand UpdateCommand = db.GetSqlStringCommand(update);
			db.AddInParameter(UpdateCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@LoaiHoKhauID", SqlDbType.Int, "LoaiHoKhauID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoSoHoKhau", SqlDbType.Int, "SoSoHoKhau", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DiaChi", SqlDbType.NVarChar, "DiaChi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TinhTPID", SqlDbType.Int, "TinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuanHuyenID", SqlDbType.Int, "QuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@PhuongXaID", SqlDbType.Int, "PhuongXaID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ToDanPhoID", SqlDbType.Int, "ToDanPhoID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HSHKSo", SqlDbType.Int, "HSHKSo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@LuuGocTap", SqlDbType.NVarChar, "LuuGocTap", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuyenSo", SqlDbType.NVarChar, "QuyenSo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ToSo", SqlDbType.Int, "ToSo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ChiBo", SqlDbType.NVarChar, "ChiBo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@GhiChu", SqlDbType.NVarChar, "GhiChu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TruongCongAnID", SqlDbType.Int, "TruongCongAnID", DataRowVersion.Current);
			
            System.Data.Common.DbCommand DeleteCommand = db.GetSqlStringCommand(delete);
			db.AddInParameter(DeleteCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);

            db.UpdateDataSet(ds, ds.Tables[0].TableName, InsertCommand, UpdateCommand, DeleteCommand, UpdateBehavior.Standard);
        }
				
		public static void UpdateDataSet(DataSet ds, string tableName)
        {
            string insert = "Insert INTO t_HoKhau VALUES(@LoaiHoKhauID, @SoSoHoKhau, @DiaChi, @TinhTPID, @QuanHuyenID, @PhuongXaID, @ToDanPhoID, @HSHKSo, @LuuGocTap, @QuyenSo, @ToSo, @ChiBo, @GhiChu, @CanBoQuanLyID, @IsDelete, @TruongCongAnID)";
            string update = "UPDATE t_HoKhau SET LoaiHoKhauID = @LoaiHoKhauID, SoSoHoKhau = @SoSoHoKhau, DiaChi = @DiaChi, TinhTPID = @TinhTPID, QuanHuyenID = @QuanHuyenID, PhuongXaID = @PhuongXaID, ToDanPhoID = @ToDanPhoID, HSHKSo = @HSHKSo, LuuGocTap = @LuuGocTap, QuyenSo = @QuyenSo, ToSo = @ToSo, ChiBo = @ChiBo, GhiChu = @GhiChu, CanBoQuanLyID = @CanBoQuanLyID, IsDelete = @IsDelete, TruongCongAnID = @TruongCongAnID WHERE ID = @ID";
            string delete = "DELETE FROM t_HoKhau WHERE ID = @ID";

			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();

            System.Data.Common.DbCommand InsertCommand = db.GetSqlStringCommand(insert);
			db.AddInParameter(InsertCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@LoaiHoKhauID", SqlDbType.Int, "LoaiHoKhauID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoSoHoKhau", SqlDbType.Int, "SoSoHoKhau", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DiaChi", SqlDbType.NVarChar, "DiaChi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TinhTPID", SqlDbType.Int, "TinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuanHuyenID", SqlDbType.Int, "QuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@PhuongXaID", SqlDbType.Int, "PhuongXaID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ToDanPhoID", SqlDbType.Int, "ToDanPhoID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HSHKSo", SqlDbType.Int, "HSHKSo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@LuuGocTap", SqlDbType.NVarChar, "LuuGocTap", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuyenSo", SqlDbType.NVarChar, "QuyenSo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ToSo", SqlDbType.Int, "ToSo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ChiBo", SqlDbType.NVarChar, "ChiBo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@GhiChu", SqlDbType.NVarChar, "GhiChu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TruongCongAnID", SqlDbType.Int, "TruongCongAnID", DataRowVersion.Current);

            System.Data.Common.DbCommand UpdateCommand = db.GetSqlStringCommand(update);
			db.AddInParameter(UpdateCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@LoaiHoKhauID", SqlDbType.Int, "LoaiHoKhauID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoSoHoKhau", SqlDbType.Int, "SoSoHoKhau", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DiaChi", SqlDbType.NVarChar, "DiaChi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TinhTPID", SqlDbType.Int, "TinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuanHuyenID", SqlDbType.Int, "QuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@PhuongXaID", SqlDbType.Int, "PhuongXaID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ToDanPhoID", SqlDbType.Int, "ToDanPhoID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HSHKSo", SqlDbType.Int, "HSHKSo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@LuuGocTap", SqlDbType.NVarChar, "LuuGocTap", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuyenSo", SqlDbType.NVarChar, "QuyenSo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ToSo", SqlDbType.Int, "ToSo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ChiBo", SqlDbType.NVarChar, "ChiBo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@GhiChu", SqlDbType.NVarChar, "GhiChu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@CanBoQuanLyID", SqlDbType.Int, "CanBoQuanLyID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TruongCongAnID", SqlDbType.Int, "TruongCongAnID", DataRowVersion.Current);
			
            System.Data.Common.DbCommand DeleteCommand = db.GetSqlStringCommand(delete);
			db.AddInParameter(DeleteCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);

            db.UpdateDataSet(ds, tableName, InsertCommand, UpdateCommand, DeleteCommand, UpdateBehavior.Standard);
        }

		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Select methods.
		
		public static HoKhau Load(int iD)
		{
			const string spName = "[dbo].[p_HoKhau_Load.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, iD);
            IDataReader reader = db.ExecuteReader(dbCommand);
			List<HoKhau> collection = ConvertToCollection(reader);	
			if (collection.Count > 0)
			{
				return collection[0];
			}
			return null;
		}		
		
		//---------------------------------------------------------------------------------------------
		public static List<HoKhau> SelectCollectionAll()
		{
			IDataReader reader = SelectReaderAll();
			return ConvertToCollection(reader);			
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public static List<HoKhau> SelectCollectionDynamic(string whereCondition, string orderByExpression)
		{
			IDataReader reader = SelectReaderDynamic(whereCondition, orderByExpression);
			return ConvertToCollection(reader);		
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		public static List<HoKhau> SelectCollectionBy_LoaiHoKhauID(int loaiHoKhauID)
		{
            IDataReader reader = SelectReaderBy_LoaiHoKhauID(loaiHoKhauID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<HoKhau> SelectCollectionBy_QuanHuyenID(int quanHuyenID)
		{
            IDataReader reader = SelectReaderBy_QuanHuyenID(quanHuyenID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<HoKhau> SelectCollectionBy_TinhTPID(int tinhTPID)
		{
            IDataReader reader = SelectReaderBy_TinhTPID(tinhTPID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<HoKhau> SelectCollectionBy_PhuongXaID(int phuongXaID)
		{
            IDataReader reader = SelectReaderBy_PhuongXaID(phuongXaID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectBy_LoaiHoKhauID(int loaiHoKhauID)
		{
			const string spName = "[dbo].[p_HoKhau_SelectBy_LoaiHoKhauID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@LoaiHoKhauID", SqlDbType.Int, loaiHoKhauID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_QuanHuyenID(int quanHuyenID)
		{
			const string spName = "[dbo].[p_HoKhau_SelectBy_QuanHuyenID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@QuanHuyenID", SqlDbType.Int, quanHuyenID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_TinhTPID(int tinhTPID)
		{
			const string spName = "[dbo].[p_HoKhau_SelectBy_TinhTPID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TinhTPID", SqlDbType.Int, tinhTPID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_PhuongXaID(int phuongXaID)
		{
			const string spName = "[dbo].[p_HoKhau_SelectBy_PhuongXaID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@PhuongXaID", SqlDbType.Int, phuongXaID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------

		public static DataSet SelectAll()
        {
            const string spName = "[dbo].[p_HoKhau_SelectAll.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			
            return db.ExecuteDataSet(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_HoKhau_SelectDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteDataSet(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
				
		public static IDataReader SelectReaderAll()
        {
            const string spName = "[dbo].[p_HoKhau_SelectAll.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
            return db.ExecuteReader(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static IDataReader SelectReaderDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_HoKhau_SelectDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteReader(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		public static IDataReader SelectReaderBy_LoaiHoKhauID(int loaiHoKhauID)
		{
			const string spName = "[dbo].[p_HoKhau_SelectBy_LoaiHoKhauID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@LoaiHoKhauID", SqlDbType.Int, loaiHoKhauID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_QuanHuyenID(int quanHuyenID)
		{
			const string spName = "[dbo].[p_HoKhau_SelectBy_QuanHuyenID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@QuanHuyenID", SqlDbType.Int, quanHuyenID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_TinhTPID(int tinhTPID)
		{
			const string spName = "[dbo].[p_HoKhau_SelectBy_TinhTPID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TinhTPID", SqlDbType.Int, tinhTPID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_PhuongXaID(int phuongXaID)
		{
			const string spName = "[dbo].[p_HoKhau_SelectBy_PhuongXaID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@PhuongXaID", SqlDbType.Int, phuongXaID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert methods.
		
		public static int InsertHoKhau(int loaiHoKhauID, int soSoHoKhau, string diaChi, int tinhTPID, int quanHuyenID, int phuongXaID, int toDanPhoID, int hSHKSo, string luuGocTap, string quyenSo, int toSo, string chiBo, string ghiChu, int canBoQuanLyID, bool isDelete, int truongCongAnID)
		{
			HoKhau entity = new HoKhau();	
			entity.LoaiHoKhauID = loaiHoKhauID;
            entity.SoSoHoKhau = soSoHoKhau;
			entity.DiaChi = diaChi;
			entity.TinhTPID = tinhTPID;
			entity.QuanHuyenID = quanHuyenID;
			entity.PhuongXaID = phuongXaID;
			entity.ToDanPhoID = toDanPhoID;
			entity.HSHKSo = hSHKSo;
			entity.LuuGocTap = luuGocTap;
			entity.QuyenSo = quyenSo;
			entity.ToSo = toSo;
			entity.ChiBo = chiBo;
			entity.GhiChu = ghiChu;
			entity.CanBoQuanLyID = canBoQuanLyID;
			entity.IsDelete = isDelete;
			entity.TruongCongAnID = truongCongAnID;
			return entity.Insert();
		}
		
		public int Insert()
		{
			return this.Insert(null);
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public int Insert(SqlTransaction transaction)
		{			
			const string spName = "[dbo].[p_HoKhau_Insert.generated]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddOutParameter(dbCommand, "@ID", SqlDbType.Int, 4);
			db.AddInParameter(dbCommand, "@LoaiHoKhauID", SqlDbType.Int, LoaiHoKhauID);
			db.AddInParameter(dbCommand, "@SoSoHoKhau", SqlDbType.Int, SoSoHoKhau);
			db.AddInParameter(dbCommand, "@DiaChi", SqlDbType.NVarChar, DiaChi);
			db.AddInParameter(dbCommand, "@TinhTPID", SqlDbType.Int, TinhTPID);
			db.AddInParameter(dbCommand, "@QuanHuyenID", SqlDbType.Int, QuanHuyenID);
			db.AddInParameter(dbCommand, "@PhuongXaID", SqlDbType.Int, PhuongXaID);
			db.AddInParameter(dbCommand, "@ToDanPhoID", SqlDbType.Int, ToDanPhoID);
			db.AddInParameter(dbCommand, "@HSHKSo", SqlDbType.Int, HSHKSo);
			db.AddInParameter(dbCommand, "@LuuGocTap", SqlDbType.NVarChar, LuuGocTap);
			db.AddInParameter(dbCommand, "@QuyenSo", SqlDbType.NVarChar, QuyenSo);
			db.AddInParameter(dbCommand, "@ToSo", SqlDbType.Int, ToSo);
			db.AddInParameter(dbCommand, "@ChiBo", SqlDbType.NVarChar, ChiBo);
			db.AddInParameter(dbCommand, "@GhiChu", SqlDbType.NVarChar, GhiChu);
			db.AddInParameter(dbCommand, "@CanBoQuanLyID", SqlDbType.Int, CanBoQuanLyID);
			db.AddInParameter(dbCommand, "@IsDelete", SqlDbType.Bit, IsDelete);
			db.AddInParameter(dbCommand, "@TruongCongAnID", SqlDbType.Int, TruongCongAnID);
			
			if (transaction != null)
			{
				db.ExecuteNonQuery(dbCommand, transaction);
				ID = (int) db.GetParameterValue(dbCommand, "@ID");
				return ID;
			}
            else
			{
				db.ExecuteNonQuery(dbCommand);
				ID = (int) db.GetParameterValue(dbCommand, "@ID");
				return ID;
			}			
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool InsertCollection(List<HoKhau> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using(SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (HoKhau item in collection)
						{
							if (item.Insert(transaction) <= 0)
							{							
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert / Update methods.
		
		public static int InsertUpdateHoKhau(int iD, int loaiHoKhauID, int soSoHoKhau, string diaChi, int tinhTPID, int quanHuyenID, int phuongXaID, int toDanPhoID, int hSHKSo, string luuGocTap, string quyenSo, int toSo, string chiBo, string ghiChu, int canBoQuanLyID, bool isDelete, int truongCongAnID)
		{
			HoKhau entity = new HoKhau();			
			entity.ID = iD;
			entity.LoaiHoKhauID = loaiHoKhauID;
			entity.SoSoHoKhau = soSoHoKhau;
			entity.DiaChi = diaChi;
			entity.TinhTPID = tinhTPID;
			entity.QuanHuyenID = quanHuyenID;
			entity.PhuongXaID = phuongXaID;
			entity.ToDanPhoID = toDanPhoID;
			entity.HSHKSo = hSHKSo;
			entity.LuuGocTap = luuGocTap;
			entity.QuyenSo = quyenSo;
			entity.ToSo = toSo;
			entity.ChiBo = chiBo;
			entity.GhiChu = ghiChu;
			entity.CanBoQuanLyID = canBoQuanLyID;
			entity.IsDelete = isDelete;
			entity.TruongCongAnID = truongCongAnID;
			return entity.InsertUpdate();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int InsertUpdate()
		{
			return this.InsertUpdate(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int InsertUpdate(SqlTransaction transaction)
		{			
			const string spName = "[dbo].p_HoKhau_InsertUpdate.generated]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);
			db.AddInParameter(dbCommand, "@LoaiHoKhauID", SqlDbType.Int, LoaiHoKhauID);
			db.AddInParameter(dbCommand, "@SoSoHoKhau", SqlDbType.Int, SoSoHoKhau);
			db.AddInParameter(dbCommand, "@DiaChi", SqlDbType.NVarChar, DiaChi);
			db.AddInParameter(dbCommand, "@TinhTPID", SqlDbType.Int, TinhTPID);
			db.AddInParameter(dbCommand, "@QuanHuyenID", SqlDbType.Int, QuanHuyenID);
			db.AddInParameter(dbCommand, "@PhuongXaID", SqlDbType.Int, PhuongXaID);
			db.AddInParameter(dbCommand, "@ToDanPhoID", SqlDbType.Int, ToDanPhoID);
			db.AddInParameter(dbCommand, "@HSHKSo", SqlDbType.Int, HSHKSo);
			db.AddInParameter(dbCommand, "@LuuGocTap", SqlDbType.NVarChar, LuuGocTap);
			db.AddInParameter(dbCommand, "@QuyenSo", SqlDbType.NVarChar, QuyenSo);
			db.AddInParameter(dbCommand, "@ToSo", SqlDbType.Int, ToSo);
			db.AddInParameter(dbCommand, "@ChiBo", SqlDbType.NVarChar, ChiBo);
			db.AddInParameter(dbCommand, "@GhiChu", SqlDbType.NVarChar, GhiChu);
			db.AddInParameter(dbCommand, "@CanBoQuanLyID", SqlDbType.Int, CanBoQuanLyID);
			db.AddInParameter(dbCommand, "@IsDelete", SqlDbType.Bit, IsDelete);
			db.AddInParameter(dbCommand, "@TruongCongAnID", SqlDbType.Int, TruongCongAnID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);			
		}
		
		//---------------------------------------------------------------------------------------------
		public static bool InsertUpdateCollection(List<HoKhau> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (HoKhau item in collection)
						{
							if (item.InsertUpdate(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertUpdateCollection method: " + ex.Message);
						
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}	
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Update methods.
		
		public static int UpdateHoKhau(int iD, int loaiHoKhauID, int soSoHoKhau, string diaChi, int tinhTPID, int quanHuyenID, int phuongXaID, int toDanPhoID, int hSHKSo, string luuGocTap, string quyenSo, int toSo, string chiBo, string ghiChu, int canBoQuanLyID, bool isDelete, int truongCongAnID)
		{
			HoKhau entity = new HoKhau();			
			entity.ID = iD;
			entity.LoaiHoKhauID = loaiHoKhauID;
			entity.SoSoHoKhau = soSoHoKhau;
			entity.DiaChi = diaChi;
			entity.TinhTPID = tinhTPID;
			entity.QuanHuyenID = quanHuyenID;
			entity.PhuongXaID = phuongXaID;
			entity.ToDanPhoID = toDanPhoID;
			entity.HSHKSo = hSHKSo;
			entity.LuuGocTap = luuGocTap;
			entity.QuyenSo = quyenSo;
			entity.ToSo = toSo;
			entity.ChiBo = chiBo;
			entity.GhiChu = ghiChu;
			entity.CanBoQuanLyID = canBoQuanLyID;
			entity.IsDelete = isDelete;
			entity.TruongCongAnID = truongCongAnID;
			return entity.Update();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int Update()
		{
			return this.Update(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Update(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_HoKhau_Update.generated]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);
			db.AddInParameter(dbCommand, "@LoaiHoKhauID", SqlDbType.Int, LoaiHoKhauID);
			db.AddInParameter(dbCommand, "@SoSoHoKhau", SqlDbType.Int, SoSoHoKhau);
			db.AddInParameter(dbCommand, "@DiaChi", SqlDbType.NVarChar, DiaChi);
			db.AddInParameter(dbCommand, "@TinhTPID", SqlDbType.Int, TinhTPID);
			db.AddInParameter(dbCommand, "@QuanHuyenID", SqlDbType.Int, QuanHuyenID);
			db.AddInParameter(dbCommand, "@PhuongXaID", SqlDbType.Int, PhuongXaID);
			db.AddInParameter(dbCommand, "@ToDanPhoID", SqlDbType.Int, ToDanPhoID);
			db.AddInParameter(dbCommand, "@HSHKSo", SqlDbType.Int, HSHKSo);
			db.AddInParameter(dbCommand, "@LuuGocTap", SqlDbType.NVarChar, LuuGocTap);
			db.AddInParameter(dbCommand, "@QuyenSo", SqlDbType.NVarChar, QuyenSo);
			db.AddInParameter(dbCommand, "@ToSo", SqlDbType.Int, ToSo);
			db.AddInParameter(dbCommand, "@ChiBo", SqlDbType.NVarChar, ChiBo);
			db.AddInParameter(dbCommand, "@GhiChu", SqlDbType.NVarChar, GhiChu);
			db.AddInParameter(dbCommand, "@CanBoQuanLyID", SqlDbType.Int, CanBoQuanLyID);
			db.AddInParameter(dbCommand, "@IsDelete", SqlDbType.Bit, IsDelete);
			db.AddInParameter(dbCommand, "@TruongCongAnID", SqlDbType.Int, TruongCongAnID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool UpdateCollection(List<HoKhau> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (HoKhau item in collection)
						{
							if (item.Update(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at UpdateCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Delete methods.
		
		public static int DeleteHoKhau(int iD)
		{
			HoKhau entity = new HoKhau();
			entity.ID = iD;
			
			return entity.Delete();
		}
		
		public int Delete()
		{
			return this.Delete(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Delete(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_HoKhau_Delete.generated]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
		
		public static int DeleteBy_LoaiHoKhauID(int loaiHoKhauID)
		{
			const string spName = "[dbo].[p_HoKhau_DeleteBy_LoaiHoKhauID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@LoaiHoKhauID", SqlDbType.Int, loaiHoKhauID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_QuanHuyenID(int quanHuyenID)
		{
			const string spName = "[dbo].[p_HoKhau_DeleteBy_QuanHuyenID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@QuanHuyenID", SqlDbType.Int, quanHuyenID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_TinhTPID(int tinhTPID)
		{
			const string spName = "[dbo].[p_HoKhau_DeleteBy_TinhTPID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TinhTPID", SqlDbType.Int, tinhTPID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_PhuongXaID(int phuongXaID)
		{
			const string spName = "[dbo].[p_HoKhau_DeleteBy_PhuongXaID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@PhuongXaID", SqlDbType.Int, phuongXaID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		
		public static int DeleteDynamic(string whereCondition)
		{
			const string spName = "[dbo].[p_HoKhau_DeleteDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            
            return db.ExecuteNonQuery(dbCommand);   
		}
		//---------------------------------------------------------------------------------------------
		
		public static bool DeleteCollection(List<HoKhau> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (HoKhau item in collection)
						{
							if (item.Delete(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at DeleteCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		#endregion
		
        //---------------------------------------------------------------------------------------------
		
        #region ICloneable Members

        public object Clone()
        {
            return base.MemberwiseClone();
        }

        public HoKhau CloneObject()
        {
            return this.Clone() as HoKhau;
        }
        
        #endregion
	}	
}